/**
 * MathExpression
 * -----------------------------------
 * 
 * - Math Expressions of Conditional Functional Dependencies
 * 
 * @author 
 */

package model.util;

public class MathExpression extends Expression {
	
	private String foundValue; //the value that was found in the document
	private String operator; // the math the expression's operator
	private String linkOperator = null; // logic operators link a math expression in another math expression 
	
	public String getLinkOperator() {
		return linkOperator;
	}
	
	public boolean setLinkOperator(String linkOperator) {
		if (linkOperator.equals("and")|| linkOperator.equals("or"))
			this.linkOperator = linkOperator;
		else 
			return false;
		return true;
	}
	
	public MathExpression(){
		super();
	}
	
	public String getFoundValue() {
		return foundValue;
	}

	public void setFoundValue(String foundValue) {
		this.foundValue = (foundValue);
	}

	public String getOperator() {
		return operator;
	}

	public boolean setOperator(String operator) {
		if (isMathOperator(operator) ) {
			this.operator = operator;
			return true;
		}
		else
			return false;				
	}
	
	
	public boolean getResult() {
		String op = getOperator();
		int i = getConstant().compareTo(getFoundValue());	
		if(op.equals("="))
			if (i == 0)
				return true;
			else
				return false;
		if(op.equals(">="))
			if (i >=0)
				return true;
			else
				return false;
		if(op.equals("<="))
			if (i <=0)
				return true;
			else
				return false;
		if(op.equals(">"))
			if (i >0)
				return true;
			else
				return false;
		if(op.equals("<"))
			if (i < 0)
				return true;
			else
				return false;
		return false;
	}


	/*public boolean getResult()
	{
		String op = getOperator();
		
		if(op.equals("="))
			if (getFoundValue() == super.getConstant())
				return true;
			else
				return false;
		if(op.equals(">="))
			if (getFoundValue() >= super.getConstant())
				return true;
			else
				return false;
		if(op.equals("<="))
			if (getFoundValue() <= super.getConstant())
				return true;
			else
				return false;
		if(op.equals(">"))
			if (getFoundValue() > super.getConstant())
				return true;
			else
				return false;
		if(op.equals("<"))
			if (getFoundValue() == super.getConstant())
				return true;
			else
				return false;
		return false;
	}*/

	/**
	 * Check if the string is a valid math operator
	 */
	public boolean isMathOperator(String token) {

		if (token.equals("=")) // equal simbol
			return true;
		if (token.equals("!=")) // not equal simbol
			return true;
		if (token.equals(">=")) // greater or equal simbol
			return true;
		if (token.equals("<=")) // less or equal simbol
			return true;
		if (token.equals(">")) // greater simbol
			return true;
		if (token.equals("<")) // less simbol
			return true;

		return false;
	}

	//public boolean validateLogicExpressions(ArrayList<String> logicOperators, )
	//{}
	
	public MathExpression(String t) {
		super(t);		
	}
}